#include "mode_brighness_config.h"


u8 brighness_level;

void init_brighness_level(u8 level)
{
    if (level <MIN_BRIGH)
    {
        brighness_level =MIN_BRIGH;
    }
    else if(brighness_level>MAX_BRIGHT)
    {
        brighness_level=MAX_BRIGHT;
    }
    else
    {   
        brighness_level=level;
    }
    LOG_INFO("brighness_level is%d\n",brighness_level);
}

void set_brighness_level(u8 level)
{
    if (level <MIN_BRIGH)
    {
        brighness_level =MIN_BRIGH;
    }
    else if(brighness_level>MAX_BRIGHT)
    {
        brighness_level=MAX_BRIGHT;
    }
    else
    {   
        brighness_level=level;
    }
    LOG_INFO("brighness_level is%d\n",brighness_level);
}

u8 get_brighness_level()
{
    return brighness_level;
}

void reduce_brighness_level(u8 reduce_level)  //降低灯管亮度
{
    if (brighness_level<reduce_level)//最小不能小于0
    {
       brighness_level=0; 
    }
    else 
    {
        brighness_level =brighness_level-reduce_level;
    }
    LOG_INFO("brighness_level is%d\n",brighness_level);
}

void add_brighness_level(u8 add_level)//增加灯光亮度
{
    if(brighness_level+add_level>MAX_BRIGHT)
    {
        brighness_level=MAX_BRIGHT;
    }
    else
    {
        brighness_level = brighness_level+add_level;
    }
    LOG_INFO("brighness_level is%d\n",brighness_level);
}


void once_brilliance_handle(SYS_OPT_KEY opt)
{
    if(OPT_GO_ADD==opt.oepation)
    {
        add_brighness_level(LIGHT_CONTINUE);
    }
    if(OPT_GO_ADD_CONTINUE==opt.oepation)
    {
        add_brighness_level(LIGHT_LEVEL);
    }
    else if(OPT_GO_REDUCE==opt.oepation)
    {
        reduce_brighness_level(LIGHT_CONTINUE);
    }
    else if(OPT_GO_REDUCE_CONTINUE==opt.oepation)
    {
        reduce_brighness_level(LIGHT_LEVEL);
    }
}


void brilliance_control_handle(SYS_OPT_KEY opt)
{
    once_brilliance_handle(opt);
}



